# -*- coding: utf-8 -*-
from web.controllers.api import route_api
from  flask import request,jsonify,g
from common.models.user import User

# from common.models.member.Member import Member
from common.libs.UrlManager import UrlManager
# from common.libs.Helper import getCurrentDate,getDictFilterField,selectFilterObj
# from application import app,db
from sqlalchemy import  or_
@route_api.route("/User/index" )
def UserIndex():
    # return
    resp = { 'code':200 ,'msg':'操作成功~','data':{} }
    # cat_list = User.query.filter_by( status = 1 ).order_by( User.uid.desc() ).all()
    # data_cat_list = []
    # data_cat_list.append({
    #     'id': 0,
    #     'name': "全部"
    # })
    # if cat_list:
    #     for item in cat_list:
    #         tmp_data = {
    #             'id':item.id,
    #             'name':item.name
    #         }
    #         data_cat_list.append( tmp_data  )
    # resp['data']['cat_list'] = data_cat_list

    food_list = User.query.filter_by( status = 1 )\
        .order_by(User.uid.desc() ).all()

    data_food_list = []
    if food_list:
        for item in food_list:
            tmp_data = {
                'id':item.uid,
                'nickname':UrlManager.buildUrl(item.nickname),
                'mobile': UrlManager.buildUrl(item.mobile),
                'email': UrlManager.buildUrl(item.email),
            }
            data_food_list.append( tmp_data )

    resp['data']['banner_list'] = data_food_list
    return jsonify( resp )